package com.weather.data.controller;

import com.weather.data.entity.VO.SkyEnginePageVO;
import com.weather.data.entity.VO.SkyEngineRespVO;
import com.weather.data.entity.VO.SkyEngineSaveVO;
import com.weather.data.result.Result;
import com.weather.data.service.SkyEngineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 天擎-接口信息 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/sky-engine")
@Api(tags = "天擎接口服务")
public class SkyEngineController {

    @Resource
    private SkyEngineService skyEngineService;

    @PostMapping("/addSkyEngine")
    @ApiOperation(value = "添加天擎接口信息")
    public Result addSkyEngine(@Validated @RequestBody SkyEngineSaveVO skyEngineSaveVO) {
        return Result.success().addBody("data", skyEngineService.addSkyEngine(skyEngineSaveVO));
    }

    @DeleteMapping("/delSkyEngineByIds")
    @ApiOperation(value = "批量删除天擎接口信息")
    @ApiImplicitParam(name = "ids", value = "id集合", dataTypeClass = String[].class)
    public Result delSkyEngineByIds(@RequestParam List<Long> ids) {
        return Result.success().addBody("data", skyEngineService.delSkyEngineByIds(ids));
    }

    @PostMapping("/updateSkyEngine")
    @ApiOperation(value = "修改天擎接口信息")
    public Result updateSkyEngine(@RequestBody SkyEngineSaveVO skyEngineSaveVO) {
        return Result.success().addBody("data", skyEngineService.updateSkyEngine(skyEngineSaveVO));
    }

    @GetMapping("/getSkyEnginePage")
    @ApiOperation(value = "查询天擎接口分页信息")
    public Result getSkyEnginePage(@RequestParam(defaultValue = "0") int page,
                                   @RequestParam(defaultValue = "10") int size,
                                   @RequestParam(required = false) String name,
                                   @RequestParam(required = false) String type,
                                   @RequestParam(required = false) String serviceNode
    ) {
        SkyEnginePageVO skyEnginePageVO = new SkyEnginePageVO();
        skyEnginePageVO.setPageNo(page);
        skyEnginePageVO.setPageSize(size);
        skyEnginePageVO.setName(name);
        skyEnginePageVO.setType(type);
        skyEnginePageVO.setServiceNodeId(serviceNode);
        return Result.success().addBody("data", skyEngineService.getSkyEnginePage(skyEnginePageVO));
    }

    @GetMapping("/getSkyEngineAndParameter")
    @ApiOperation(value = "查询详情")
    @ApiImplicitParam(value = "id", name = "id", dataTypeClass = Long.class)
    public Result getSkyEngineAndParameter(@RequestParam Long id) {
        return Result.success().addBody("data", skyEngineService.getSkyEngineAndParameter(id));
    }

    @PostMapping("/downloadFile")
    @ApiOperation(value = "下载文件")
    public Result downloadFile(@RequestBody SkyEngineRespVO skyEngineRespVO) throws IOException {
        return Result.success().addBody("data", skyEngineService.downloadFile(skyEngineRespVO));
    }


}
